<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理系统</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            min-width: 1000px;
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .box {
            width: 50%;
            height: 70%;
            /* background-color: red; */
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        ul {
            list-style: none;
            width: 100%;
            height: 90%;
            overflow: auto;
        }

        li {
            height: 10%;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        li>div {
            box-sizing: border-box;
            border: 1px solid black;
            font-size: 1.5vw;
            height: 100%;
            width: 25%;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>

<body>
    <div class="box">
        <h1>用户管理系统</h1>
        <ul class="list">
            <li>
                <div>序号</div>
                <div>昵称</div>
                <div>年龄</div>
                <div>密码</div>
            </li>
        </ul>
    </div>

    <script>
        let list = document.querySelector('.list');
        findAll();
        
        function findAll(){
            axios.get('/api/findAll', {})
            .then(res => {
                console.log(res);
                const lists = res.data.info;
                lists.forEach((item, index) => {
                    let li = document.createElement('li');
                    li.setAttribute('_id',item._id);
                    li.innerHTML =
                        `
                        <div>${index+1}</div>
                        <div>${item.name}</div>
                        <div>${item.age}</div>
                        <div>${item.password}</div>
                        `
                    list.appendChild(li);
                });
            })
            .catch(err => {
                console.error(err);
            })
        }
    </script>
</body>

</html>